#!/bin/sh 
#set -x

cd $1

ADDR=$2
DAYS=365

ALTNAME=$3
export ALTNAME


rm -f demoCA/index.txt
touch demoCA/index.txt
rm -f demoCA/newcerts/*

echo "CSR was bad" > ${ADDR}.cer

openssl ca -extensions cj_cert -config openssl.cnf \
    -passin pass:password -policy policy_anything \
    -md sha1 -days ${DAYS} -batch -notext -out ${ADDR}.cer \
    -infiles ${ADDR}.csr

ret=$?

if [ $ret -ne 0 ];then
    echo "CSR was bad" > ${ADDR}.cer
    exit 1;
fi
